//题目链接：https://www.luogu.com.cn/problem/P3366#submit
#include <iostream>
#include <algorithm>
using namespace std;

int n , m;
const int N = 5010 , M = 200010;
int p[N];
struct Edge
{
    int a , b , w;
    bool operator<(Edge& e)
    {
        return w < e.w;
    }
}edges[M];

int find(int x)
{
    if(x != p[x]) p[x] = find(p[x]);
    return p[x];
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i = 0 ; i < m ; ++i)
    {
        int a , b , w;
        cin >> a >> b >> w;
        edges[i] = {a,b,w};
    }
    
    sort(edges,edges + m);
    for(int i = 1 ; i <= n ; ++i) p[i] = i;
    
    int res = 0 , cnt = 0;
    for(int i = 0 ; i < m; ++i)
    {
        int a = edges[i].a , b = edges[i].b , w = edges[i].w;
        a = find(a);
        b = find(b);
        if(a != b)
        {
            p[a] = b;
            res += w;
            cnt++;
        }
    }
    if(cnt < n-1) printf("orz");
    else printf("%d",res);
    return 0;
}